var mno="null";
$(function(){	
	$.post("../../menberInfo/checkLogin", null , function(data){
		
			mno=data.mno;
			getOrder();
		} , "json");		
	
	// 查询订单信息
	/*$.post("order/getOrder", null, function(data){
		var str = "";
		var totalCount = 0;
		var totalPrice = 0;
		$.each(data, function(index, item) {
			str += '<ul class="goods_list_td clearfix"><li class="col01">'+(index + 1)+'</li>';
			str += '<li class="col02"><img src="'+item.pics.split(";")[0]+'"></li><li class="col03">'+item.gname+'</li>';
			str += '<li class="col04">'+item.weight+'</li><li class="col05">'+item.price+'元</li><li class="col06">'+item.nums+'</li>';
			str += '<li class="col07">'+(item.nums * item.price).toFixed(2)+'元</li></ul>';

			totalCount += item.nums;
			totalPrice += parseFloat((item.nums * item.price).toFixed(2));
		});
		
		$("#order_list").append($(str));
		$("#total_count").text(totalCount);
		$("#total_price").text(totalPrice.toFixed(2) + "元");
		$("#real_price").text((totalPrice + 10).toFixed(2) + "元");
	}, "json")*/
})

function getOrder(){
	var str='';
	$.post("../../orderInfo/getOrder", {mno:mno}, function(data){
		var ono=0;
		var total=0;
		for(var i=0;i<data.length;i++){			
			var n=1;			
			if(ono!=data[i].ono){
				if(data[i].status==0){//未支付																	//../../index.jsp?price='+data[i].price+'				
					str+='<div class="order_title">'+data[i].odate+'&nbsp;&nbsp;&nbsp;&nbsp; 订单号：'+data[i].ono+'<a href="../../index.jsp?price='+data[i].price+'&ono='+data[i].ono+'">去支付</a></div>';
				}else{
					str+='<div class="order_title">'+data[i].odate+'&nbsp;&nbsp;&nbsp;&nbsp; 订单号：'+data[i].ono+'<a href="javascript:void(0)">已完成</a></div>';
				}
				ono=data[i].ono;
				
				for(var j=0;j<data.length;j++){
					if(ono==data[j].ono){						
						str+='<ul class="goods_list_td clearfix">';
						str+='<li class="col01">'+n+'</li>';
						str+='<li class="col02"><img src="../../'+data[j].pics+'"></li>';
						str+='<li class="col03">'+data[j].gname+'</li>';
						str+='<li class="col04">'+data[j].unit+'</li>';
						str+='<li class="col04">'+data[j].prices+'元</li>';
						str+='<li class="col03">'+data[j].nums+'</li>';
						total=parseInt(data[j].prices*data[j].nums);
						str+='<li class="col04">'+total+'元</li>	 </ul>';
						n++;
					}
				}				
			}	
		}
		$("#order_list").html(str);
	},"json");
}


$('#order_btn').click(function() {

	$('.popup_con').fadeIn('fast', function() {

		setTimeout(function(){
			$('.popup_con').fadeOut('fast',function(){
				window.location.href = '../../index.html';
			});	
		},3000)
		
	});
});
//搜索
function find(){
	var str=$("#inp").val();
	$.post("../../goodsInfo/find",{str:str},function(data){
		console.log(data);
		if(data==null){
			alert("抱歉,没有该商品...");
			console.log("抱歉,没有该商品...");
		}else{					
			location.href="../../details.html?gno="+data.gno;
		}
	},"json");
}

